<?php

namespace App\Models;

use App\Models\Concerns\UserHasAbility;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable
{
    // 功能性辅助相关。
    use Notifiable,
        Common,
        HasApiTokens,
        SoftDeletes,
        UserHasAbility;
    // 关系数据相关
    use Relations\UserHasRole;
    const STATUS = [//状态
        0 => '禁用',
        1 => '正常',
    ];
    protected $table = 'users';

    protected $casts = ['identity_photo' => 'array'];


    protected $fillable = ['phone', 'company_id'];


    /**
     * 复用设置手机号查询条件方法
     *
     * @param Builder $query
     * @param string $phone
     * @return Builder
     * @author Bob(bobcoder@qq.com)
     */
    public function scopeByPhone(Builder $query, string $phone): Builder
    {
        return $query->where('phone', $phone);
    }


    /**
     * 公司
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @Author 姿势就是力量
     */
    public function company()
    {
        return $this->belongsTo(Company::class, 'company_id', 'id');
    }

}
